<%@ page
	import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
<%
		try {
		session = request.getSession();

		//	temporary removed enable this line for login, and remove if(false){
		if (session.getAttribute("USER_ID") == null
		|| !((String) session.getAttribute("SESSION_ID"))
				.equals(session.getId())) {

			//	if(false){
			try {
		response.sendRedirect("LoginPage.jsp");
			} catch (IOException ioe) {
		ioe.printStackTrace();
			}

		} else {


			
			DBUtil dbutil = new DBUtil(getServletContext());
			String userid = (String) session.getAttribute("USER_ID") == null ? ""
			: (String) session.getAttribute("USER_ID");
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<title>Admin - Data Server Info</title>
<script>

	function trim(sString)
		  {
			sTrimmedString = "";
		   if (sString != "") {
			  var iStart = 0;
			  var iEnd = sString.length - 1;
			 // var sWhitespace = " \t\f\n\r\v";
			 var sWhitespace = "   ";


			  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				 iStart++;
				 if (iStart > iEnd) 
					break;
			  }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }

	
	function checkForEmpty(DataServer,IP,NYShortPath,LNShortPath,RefreshFreq,DBsRefreshed,DataserverHost){
		  	
					// alert("obj.value.length"+obj.value);
			
				DataServer.value = trim(DataServer.value);
				IP.value = trim(IP.value);
				NYShortPath.value = trim(NYShortPath.value);
				LNShortPath.value = trim(LNShortPath.value);
				RefreshFreq.value = trim(RefreshFreq.value);
				DBsRefreshed.value = trim(DBsRefreshed.value);
				DataserverHost.value = trim(DataserverHost.value);
	
				if (DataServer.value.length == 0 )
				{
					alert("Please enter Data Server Name");
					DataServer.focus();
					return false;
				}
				if (DataserverHost.value.length == 0 )
				{
					alert("Please enter Data Server Host name");
					DataserverHost.focus();
					return false;
				}
				if (IP.value.length == 0 )
				{
					alert("Please enter IP address");
					IP.focus();
					return false;
				}
				if (NYShortPath.value.length == 0 )
				{
					alert("Please enter NY Shortcut Path");
					NYShortPath.focus();
					return false;
				}
				if (LNShortPath.value.length == 0 )
				{
					alert("Please enter LN Shortcut Path");
					LNShortPath.focus();
					return false;
				}
				if (RefreshFreq.value.length == 0 )
				{
					alert("Please enter Refresh Freq.");
					RefreshFreq.focus();
					return false;
				}
				if (DBsRefreshed.value.length == 0 )
				{
					alert("Please enter name of Databases refreshed.");
					DBsRefreshed.focus();
					return false;
				}

				document.AddDataServerForm.submit();
				
		} 	
	
	function openDataServerDetails(DataServerID) {
		dwin=window.open("EditDataServerInfo.jsp?DataServerID="+DataServerID,"detailWin","width=700,height=300,scrollbars=yes,resizable=No");
		dwin.focus();
		
		}

	</script>
</head>

<body>
<table width="100%">
	<tr>
		<td width=100%><jsp:include page="HeaderNav_ReleaseObject.jsp" /></td>
	</tr>
</table>
<%
			String AddServerInfoButton = request.getParameter("AddServerInfoButton") == null ? ""	: request.getParameter("AddServerInfoButton");

			if (AddServerInfoButton.equals("Add")) {
		
				boolean addSuccessFlag = false;				

				String DataServer = request.getParameter("DataServer") == null ? "" : request.getParameter("DataServer");
				String IP = request.getParameter("IP") == null ? ""	: request.getParameter("IP");
				String NYShortPath = request.getParameter("NYShortPath") == null ? ""	: request.getParameter("NYShortPath");
				String LNShortPath = request.getParameter("LNShortPath") == null ? "" : request.getParameter("LNShortPath");
				String RefreshFreq = request.getParameter("RefreshFreq") == null ? "" : request.getParameter("RefreshFreq");
				String DBsRefreshed = request.getParameter("DBsRefreshed") == null ? "" : request.getParameter("DBsRefreshed");
				String DataserverHost = request.getParameter("DataserverHost") == null ? "" : request.getParameter("DataserverHost");
				String Remarks = request.getParameter("Remarks") == null ? "" : request.getParameter("Remarks");
				
				addSuccessFlag = dbutil.addNewDataServerInfo(DataServer, IP, NYShortPath, LNShortPath, RefreshFreq, DBsRefreshed, DataserverHost, Remarks, userid);
				
				if(addSuccessFlag == false){
					%>
					<script>
							alert("Error while adding new data server info!");
					</script>
					<% 
				}

			}


			Vector dataServerInfo = dbutil.getDataServerInfo();
%>




<a href="mainpage.jsp">Back to Main.</a>
<a href="ReleaseAdmin.jsp">Back to Admin Page</a>
<table>
	<tr>
		<td align=right>&nbsp</td>
	</tr>
</table>


<form name="AddDataServerForm" action="AdminDataServerInfo.jsp" method="post">
<table cellpadding="0" cellspacing="1" width="50%" style="BORDER:#000000 1px solid" align='center' colspan=2>

	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=2><b>Add Data Server Information</b></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Data Server</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="DataServer" size="40">
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Dataserver Host Name</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="DataserverHost" size="40">	
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">IP Address</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="IP" size="40">
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">NY Shortcut Path</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="NYShortPath" size="40">
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">LN Shortcut Path</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type=text name="LNShortPath" size="40">
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Refresh (Freq)</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="RefreshFreq" size="40">	
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Databases Refreshed</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="DBsRefreshed" size="40">	
		</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Remarks</td>
		<td class=bodyblue align=left colspan="1" width="70%">
			<input type="text" name="Remarks" size="40">	
		</td>
	</tr>
	
	<tr bgcolor=#EFEFEF>
		<td class="bodyblue" colspan="2" align="right">
			<input type=submit class=whitebutton name=AddServerInfoButton value="Add"
			onclick="return checkForEmpty(DataServer,IP,NYShortPath,LNShortPath,RefreshFreq,DBsRefreshed,DataserverHost)"
			align=right></td>
	</tr>

</table>
</form>


<table>
	<tr>
		<td>&nbsp</td>
	</tr>
</table>
<table cellpadding="0" cellspacing="1" width="90%"
	style="BORDER:#000000 1px solid" align='center' colspan=9>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=9><b>Data Server Info</b></td>
	</tr>

	<%
				if (dataServerInfo != null && dataServerInfo.size() > 0) {
	%>
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left width='2%' colspan=1><b>#</b></td>
		<td class=smallfonthead align=left width='10%' colspan=1><b>Data Server</b></td>
		<td class=smallfonthead align=left width='15%' colspan=1><b>Dataserver Host Name</b></td>
		<td class=smallfonthead align=left width='13%' colspan=1><b>IP Address</b></td>
		<td class=smallfonthead align=left width='10%' colspan=1><b>NY Shortcut Path</b></td>
		<td class=smallfonthead align=left width='10%' colspan=1><b>LN Shortcut Path</b></td>
		<td class=smallfonthead align=left width='10%' colspan=1><b>Refreshed (Freq)</b></td>
		<td class=smallfonthead align=left width='15%' colspan=1><b>Databases Refreshed</b></td>
		<td class=smallfonthead align=left width='15%' colspan=1><b>Remarks</b></td>
	</tr>	
	<% 
			for (int i = 0; i < dataServerInfo.size(); i++) {
				DBServerBean serverBean = (DBServerBean) dataServerInfo.elementAt(i);
	%>


	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=center><%=i + 1%></td>
		<td class=bodyblue align=left><a
			href="javascript:openDataServerDetails('<%=serverBean.getDataServerID()%>')"><%=serverBean.getDataServer()%></a></td>
		<td class=bodyblue align=left><%=serverBean.getDataServerHost()%></td>
		<td class=bodyblue align=left><%=serverBean.getIP()%></td>
		<td class=bodyblue align=left><%=serverBean.getNYShortPath()%></td>	
		<td class=bodyblue align=left><%=serverBean.getLNShortPath()%></td>
		<td class=bodyblue align=left><%=serverBean.getRefreshFreq()%></td>
		<td class=bodyblue align=left><%=serverBean.getDBsRefreshed()%></td>
		<td class=bodyblue align=left><%=serverBean.getRemarks()%></td>
	</tr>
	
	

	<%
				}
				} else {
	%>
	<tr bgcolor=#000077>
		<td class=smallfonthead align="center" colspan=9><b>Not any Data Server Information found...</b></td>
	</tr>
	<%
	}
	%>
</table>



</body>
</html>





<%
	}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
